{% extends "personal_center/base.html" %}

{% block page_link %}
    <link rel="stylesheet" href="../../static/technological/css/style.css">
{% endblock %}


{% block style %}
    <style>
        .add_class {
            background: #1E90FF;
        }
        .add_background {
            background: #A9A9A9;
        }
        tr td {
            height: 35px;padding-right: 5px;outline: none;
        }
        th {
            text-align: center;
        }
        .file {
            position: relative;display: inline-block;background: #D0EEFF;border: 1px solid #99D3F5;border-radius: 4px;padding: 4px 12px;overflow: hidden;color: #1E88C7;text-decoration: none;text-indent: 0;line-height: 20px;
        }
        .file input {
            position: absolute;font-size: 100px;right: 0;top: 0;opacity: 0;
        }
        .file:hover {
            background: #AADFFD;border-color: #78C3F3;color: #004974;text-decoration: none;
        }
    </style>
{% endblock %}


{% block right_content %}
    <div class="headline">
        <div style="width: 15%;height: 100%;line-height: 40px;float: left;padding-left: 1%;">
            <a href="#" style="color: #0b0b0b;">
                <i class="iconfont icon-faqi"></i>
                <a href="Javascript:;" style="color: #0b0b0b;">职工出国（境）审批</a>
            </a>
        </div>
        <div style="height: 100%;line-height: 40px;float: right;text-align: right;padding-right: 15px;">
            <button id="add_station" type="button" style="width: 100px;height: 30px;margin-top: 5px;border-radius: 3px;border: #1E90FF solid 1px;background-color: #1E90FF;color: white;line-height: 25px;"
                    onclick="save_data()">
                保存
            </button>
        </div>

        <div style="width: 15%;height: 100%;line-height: 40px;float: right;text-align: right;padding-right: 15px;">
            <button id="add_station" type="button" style="width: 100px;height: 30px;margin-top: 5px;border-radius: 3px;border: #1E90FF solid 1px;background-color: #1E90FF;color: white;line-height: 25px;" onclick="submit_data()">
                提交
            </button>
        </div>
    </div>
    <hr>

    <div style="width: 100%;height: 95%;">
        <div id="menu_from" style="width: 100%;height: 100%;color: #2C3E50;display: inline-block;vertical-align: top;background: white;overflow: auto;padding-top: 20px;padding-bottom: 100px;">
            <table style="width: 90%;margin-left: 5%;">
                <tr style="width: 100%;">
                    <td colspan="6" style="width: 100%;height: 40px;padding-left: 0.5%;line-height: 40px;border: #cfcfcf solid 1px;text-align: center;"><h3 id="form_name">京山市人民医院职工出国（境）审批表</h3></td>
                </tr>
                <tr style="width: 100%;">
                    <td colspan="6" style="width: 100%;height: 35px;background: #F5F5F5;padding-left: 0.5%;line-height: 40px;border-right: #cfcfcf solid 1px;border-left: #cfcfcf solid 1px;color: #00a0e9;">申请详情</td>
                </tr>
                <tr style="margin-left: 1%;">
                    <td style="width: 10%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;letter-spacing: 2.2px;">
                        <p style="width: 90px;float: right;text-align-last: justify;">姓名</p>
                    </td>
                    <td id="applicat" style="width: 20%;height: 35px;line-height: 35px;padding-left: 1%;border: #cfcfcf solid 0.5px;">{{ realname }}</td>
                    <td style="width: 10%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;">
                        <p style="width: 90px;float: right;text-align-last: justify;">工号</p>
                    </td>
                    <td id="job_number" style="width: 20%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;">{{ job_number }}</td>
                    <td style="width: 10%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;">
                        <p style="width: 90px;float: right;text-align-last: justify;">科室</p>
                    </td>
                    <td id="company" style="width: 30%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;">{{ department }}</td>
                </tr>
                <tr style="margin-left: 1%;">
                    <td style="width: 10%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;letter-spacing: 2.2px;border-top: none;">
                        <p style="width: 90px;float: right;text-align-last: justify;">进院时间</p>
                    </td>
                    <td id="entry_time" style="width: 20%;height: 35px;line-height: 35px;padding-left: 1%;border: #cfcfcf solid 0.5px;border-top: none;" contenteditable="true"></td>
                    <td style="width: 10%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;border-top: none;">
                        <p style="width: 90px;float: right;text-align-last: justify;">入党时间</p>
                    </td>
                    <td id="join_party_time" style="width: 20%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;border-top: none;" contenteditable="true"></td>
                    <td style="width: 10%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;border-top: none;">
                        <p style="width: 90px;float: right;text-align-last: justify;">所在职务</p>
                    </td>
                    <td style="width: 30%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;border-top: none;">
                        <select name="" id="position" style="width: 100%;height: 100%;border: none;outline: none;">
                            <option value="0">请选择所在职务</option>
                            <option value="1">院领导</option>
                            <option value="2">科主任</option>
                            <option value="3">副主任</option>
                            <option value="4">护士长</option>
                            <option value="5">其他</option>
                        </select>
                    </td>
                </tr>
                <tr style="margin-left: 1%;">
                    <td style="width: 10%;border: #cfcfcf solid 0.5px;text-align: right;height: 50px;border-top: none;">
                        <p style="width: 90px;float: right;text-align-last: justify;">前往<br>国家/地区</p>
                    </td>
                    <td id="onwards_country" colspan="3" style="width: 50%;height: 50px;line-height: 50px;padding-left: 1%;border: #cfcfcf solid 0.5px;border-top: none;" contenteditable="true"></td>
                    <td style="width: 10%;border: #cfcfcf solid 0.5px;text-align: right;height: 50px;border-top: none;">
                        <p style="width: 90px;float: right;text-align-last: justify;">人员类别</p>
                    </td>
                    <td style="width: 30%;height: 50px;line-height: 50px;border: #cfcfcf solid 0.5px;border-top: none;">
                        <select name="" id="position_identity" style="width: 100%;height: 100%;border: none;outline: none;">
                            <option value="0">请选择人员类别</option>
                            <option value="1">行管</option>
                            <option value="2">医技/临床</option>
                            <option value="3">护理</option>
                        </select>
                    </td>
                </tr>
                <tr style="margin-left: 1%;">
                    <td rowspan="2" style="width: 10%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;border-top: none;">
                        <p style="width: 90px;float: right;text-align-last: justify;">国外<br>通讯处</p>
                    </td>
                    <td style="width: 20%;height: 35px;line-height: 35px;border: #cfcfcf solid 0.5px;border-top: none;text-align: center;">
                        中文
                    </td>
                    <td id="mailing_address_ch" colspan="4" style="width: 70%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;border-top: none;" contenteditable="true"></td>
                </tr>
                <tr style="margin-left: 1%;">
                    <td style="width: 20%;height: 35px;line-height: 35px;border: #cfcfcf solid 0.5px;border-top: none;text-align: center;">
                        外文
                    </td>
                    <td id="mailing_address_en" colspan="4" style="width: 70%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;border-top: none;" contenteditable="true"></td>
                </tr>
                <tr style="margin-left: 1%;">
                    <td style="width: 10%;border: #cfcfcf solid 0.5px;text-align: right;height: 50px;border-top: none;">
                        <p style="width: 90px;float: right;text-align-last: justify;">申请理由<br>及期限</p>
                    </td>
                    <td id="application_reason" colspan="5" style="width: 20%;height: 50px;line-height: 50px;padding-left: 1%;border: #cfcfcf solid 0.5px;border-top: none;" contenteditable="true"></td>
                </tr>
                <tr style="margin-left: 1%;">
                    <td style="width: 10%;border: #cfcfcf solid 0.5px;text-align: right;height: 150px;border-top: none;">
                        <p style="width: 90px;float: right;text-align-last: justify;">国内直系<br>亲属及主<br>要社会关<br>系情况</p>
                    </td>
                    <td id="social_relations_ch" colspan="5" style="width: 20%;height: 150px;padding-left: 1%;border: #cfcfcf solid 0.5px;border-top: none;" contenteditable="true"></td>
                </tr>
                <tr style="margin-left: 1%;">
                    <td style="width: 10%;border: #cfcfcf solid 0.5px;text-align: right;height: 150px;border-top: none;">
                        <p style="width: 90px;float: right;text-align-last: justify;">国外直系<br>亲属及主<br>要社会关<br>系情况</p>
                    </td>
                    <td id="social_relations_en" colspan="5" style="width: 20%;height: 150px;padding-left: 1%;border: #cfcfcf solid 0.5px;border-top: none;" contenteditable="true"></td>
                </tr>
                <tr style="margin-left: 1%;">
                    <td style="width: 10%;border: #cfcfcf solid 0.5px;text-align: right;height: 150px;border-top: none;">
                        <p style="width: 90px;float: right;text-align-last: justify;">是否有《职工出国（境）管理办法》中规定的不得批准出国（境）的情况</p>
                    </td>
                    <td id="restrictive_conditions" colspan="5" style="width: 20%;height: 150px;padding-left: 1%;border: #cfcfcf solid 0.5px;border-top: none;" contenteditable="true"></td>
                </tr>
            </table>
            <table style="width: 90%;margin-left: 5%;">
                <thead>
                    <tr style="width: 100%;">
                        <td colspan="6" style="width: 95%;margin-left: 2.5%;height: 40px;padding-left: 0.5%;line-height: 40px;background: #F5F5F5;border: #cfcfcf solid 1px;border-top: none;color: #00a0e9;">
                            上传附件
                            <a href="javascript:;" class="file" style="vertical-align: top;margin-top: 5px;float: right;">
                                上传文件
                                <input type="file" name="party_main_body" id="party_main_body"
                                       onchange="upload_accessory('file1', 'party_main', 'party_main_body')">
                            </a>
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 5%;border: #cccccc solid 1px;text-align: center;">序号</td>
                        <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                            文件名称
                        </td>
                        <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                            文件大小
                        </td>
                        <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                            上传时间
                        </td>
                        <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                            上传人员
                        </td>
                        <td style="width: 15%;border: #cccccc solid 1px;border-left: none;text-align: center;">操作
                        </td>
                    </tr>
                </thead>
                <tbody style="overflow: auto;" id="party_main"></tbody>
            </table>
        </div>
    </div>
{% endblock %}

{% block script %}
    <script type="text/javascript" src="../../static/public_file/other/jquery.js"></script>
    <script type="text/javascript">
        window.onload = function () {
            document.getElementById("sponsor").className = "add_class";
            document.getElementById("personage").className = "add-nav-active";
        };

        const fj_number = '{{ uuid }}'

        function submit_data() {
            var form = new FormData();
            var entry_time = document.getElementById('entry_time').innerText;
            var join_party_time = document.getElementById('join_party_time').innerText;
            var position = document.getElementById('position').value;
            var onwards_country = document.getElementById('onwards_country').innerText;
            var position_identity = document.getElementById('position_identity').value;
            var mailing_address_ch = document.getElementById("mailing_address_ch").innerText;
            var mailing_address_en = document.getElementById("mailing_address_en").innerText;
            var application_reason = document.getElementById("application_reason").innerText;
            var social_relations_ch = document.getElementById('social_relations_ch').innerText;
            var social_relations_en = document.getElementById('social_relations_en').innerText;
            var restrictive_conditions = document.getElementById('restrictive_conditions').innerText;

            if (!entry_time) {
                alert('进院时间不能为空！')
                return false
            }
            if (position === '0') {
                alert('请选择所在职务！')
                return false
            }
            if (!onwards_country) {
                alert('前往国家/地区不能为空！')
                return false
            }
            if (position_identity === '0') {
                alert('请选择人员类别！')
                return false
            }
            if (!mailing_address_ch) {
                alert('国外通讯处中文不能为空！')
                return false
            }
            if (!mailing_address_en) {
                alert('国外通讯处英文不能为空！')
                return false
            }
            if (!application_reason) {
                alert('申请理由及期限不能为空！')
                return false
            }
            if (!social_relations_ch) {
                alert('国内直系亲属及主要社会关系情况不能为空！')
                return false
            }
            if (!social_relations_en) {
                alert('国外直系亲属及主要社会关系情况不能为空！')
                return false
            }
            if (!restrictive_conditions) {
                alert('是否有《职工出国（境）管理办法》中规定的不得批准出国（境）的情况不能为空！')
                return false
            }
            document.getElementById("loading").style.display = "inline-block";

            form.append("entry_time", entry_time);
            form.append('join_party_time', join_party_time)
            form.append('position', position)
            form.append('onwards_country', onwards_country)
            form.append('position_identity', position_identity)
            form.append('mailing_address_ch', mailing_address_ch)
            form.append('mailing_address_en', mailing_address_en)
            form.append('application_reason', application_reason)
            form.append('social_relations_ch', social_relations_ch)
            form.append('social_relations_en', social_relations_en)
            form.append('restrictive_conditions', restrictive_conditions)
            form.append('fj_number', fj_number)
            var xhr = new XMLHttpRequest();
            xhr.open('post', "/new-flow-logic/employees_abroad_index.html", true);
            xhr.send(form);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        var JsonDate = JSON.parse(xhr.responseText);
                        if (JsonDate["code"] === 200) {
                            alert("创建成功");
                            window.location = "/new-flow-logic/employees_abroad_list.html";
                        } else {
                            alert(JsonDate['message']);
                            document.getElementById("loading").style.display = "none";
                        }
                    }
                }
             };
        }

        function save_data() {
            var form = new FormData();
            var entry_time = document.getElementById('entry_time').innerText;
            var join_party_time = document.getElementById('join_party_time').innerText;
            var position = document.getElementById('position').value;
            var onwards_country = document.getElementById('onwards_country').innerText;
            var position_identity = document.getElementById('position_identity').value;
            var mailing_address_ch = document.getElementById("mailing_address_ch").innerText;
            var mailing_address_en = document.getElementById("mailing_address_en").innerText;
            var application_reason = document.getElementById("application_reason").innerText;
            var social_relations_ch = document.getElementById('social_relations_ch').innerText;
            var social_relations_en = document.getElementById('social_relations_en').innerText;
            var restrictive_conditions = document.getElementById('restrictive_conditions').innerText;

            document.getElementById("loading").style.display = "inline-block";

            form.append("entry_time", entry_time);
            form.append('join_party_time', join_party_time)
            form.append('position', position)
            form.append('onwards_country', onwards_country)
            form.append('position_identity', position_identity)
            form.append('mailing_address_ch', mailing_address_ch)
            form.append('mailing_address_en', mailing_address_en)
            form.append('application_reason', application_reason)
            form.append('social_relations_ch', social_relations_ch)
            form.append('social_relations_en', social_relations_en)
            form.append('restrictive_conditions', restrictive_conditions)
            form.append('fj_number', fj_number)
            var xhr = new XMLHttpRequest();
            xhr.open('post', "/new-flow-logic/employees_abroad_draft.html", true);
            xhr.send(form);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        var JsonDate = JSON.parse(xhr.responseText);
                        if (JsonDate["code"] === 200) {
                            alert("保存成功！");
                            window.location = "/new-flow-logic/employees_abroad_list.html";
                        } else {
                            alert(JsonDate['message']);
                            document.getElementById("loading").style.display = "none";
                        }
                    }
                }
             };
        }

        // 上传附件
        function upload_accessory(file_type, tbody_id, accessory_type) {
            document.getElementById("loading").style.display = "inline-block";
            var form = new FormData();
            var files = document.getElementById(accessory_type).files[0];
            form.append(file_type, files);
            form.append('number', fj_number)
            form.append('source', 'cgsp')
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/administrative/topics_attachments_upload", true);
            xhr.send(form);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        creat_table(JsonDate, tbody_id)
                    }
                }
            };
        }

        // 创建附件列表
        function creat_table(JsonData, tbody_id) {
            var t_table = document.getElementById(tbody_id);
            var local_host = window.location.host;
            if (Array.isArray(JsonData["pdf_path"])) {
                for (var i = 0; i < JsonData["pdf_path"].length; i++) {
                    var tr = document.createElement("tr");var td1 = document.createElement("td");var td2 = document.createElement("td");var td3 = document.createElement("td");var td4 = document.createElement("td");var td5 = document.createElement("td");var td6 = document.createElement("td");
                    td1.innerHTML = t_table.children.length + 1;td1.style.textAlign = "center";td1.style.border = "#cccccc solid 1px";td1.style.borderTop = "none";
                    td2.innerHTML = JsonData["file_name"];td2.style.paddingLeft = "1%";td2.style.border = "#cccccc solid 1px";td2.style.borderLeft = "none";td2.style.borderTop = "none";
                    td3.innerHTML = JsonData["file_size"];td3.style.textAlign = "center";td3.style.border = "#cccccc solid 1px";td3.style.borderLeft = "none";td3.style.borderTop = "none";
                    td4.innerHTML = JsonData["upload_time"];td4.style.textAlign = "center";td4.style.border = "#cccccc solid 1px";td4.style.borderLeft = "none";td4.style.borderTop = "none";
                    td5.innerHTML = JsonData["uploader"];td5.style.textAlign = "center";td5.style.border = "#cccccc solid 1px";td5.style.borderLeft = "none";td5.style.borderTop = "none";
                    td6.innerHTML = "<a target='_blank' href='" + JsonData["pdf_path"][i]["pdf_path"] + "'>查看</a> | <a style='color: red;' href='#' onclick='RemoveTr(this, \"" + tbody_id + "\", \"" + JsonData["pdf_path"][i]["id"] + "\")'>删除</a>";
                    td6.style.textAlign = "center";td6.style.border = "#cccccc solid 1px";td6.style.borderLeft = "none";td6.style.borderTop = "none";
                    tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td3);tr.appendChild(td4);tr.appendChild(td5);tr.appendChild(td6);
                    t_table.appendChild(tr);
                }
                if (JsonData["pdf_path"].length > 1) {
                    document.getElementById("del_adjunct").style.display = 'block';
                }
            } else {
                tr = document.createElement("tr");td1 = document.createElement("td");td2 = document.createElement("td");td3 = document.createElement("td");td4 = document.createElement("td");td5 = document.createElement("td");td6 = document.createElement("td");
                td1.innerHTML = t_table.children.length + 1;td1.style.textAlign = "center";td1.style.border = "#cccccc solid 1px";td1.style.borderTop = "none";
                td2.innerHTML = JsonData["file_name"];td2.style.paddingLeft = "1%";td2.style.border = "#cccccc solid 1px";td2.style.borderLeft = "none";td2.style.borderTop = "none";
                td3.innerHTML = JsonData["file_size"];td3.style.textAlign = "center";td3.style.border = "#cccccc solid 1px";td3.style.borderLeft = "none";td3.style.borderTop = "none";
                td4.innerHTML = JsonData["upload_time"];td4.style.textAlign = "center";td4.style.border = "#cccccc solid 1px";td4.style.borderLeft = "none";td4.style.borderTop = "none";
                td5.innerHTML = JsonData["uploader"];td5.style.textAlign = "center";td5.style.border = "#cccccc solid 1px";td5.style.borderLeft = "none";td5.style.borderTop = "none";
                td6.innerHTML = "<a target='_blank' href='" + JsonData["pdf_path"] + "'>查看</a> | <a style='color: red;' href='#' onclick='RemoveTr(this, \"" + tbody_id + "\", \"" + JsonData["id"] + "\")'>删除</a>";
                td6.style.textAlign = "center";td6.style.border = "#cccccc solid 1px";td6.style.borderLeft = "none";td6.style.borderTop = "none";
                tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td3);tr.appendChild(td4);tr.appendChild(td5);tr.appendChild(td6);t_table.appendChild(tr);
            }
        }

        function RemoveTr(_this, tbody_id, wj_id) {
            var table = document.getElementById(tbody_id);
            var trNode = $(_this).parent().parent();
            trNode.remove();

            for (var i=0; i<table.children.length; i++){
                table.children[i].children[0].innerHTML=i+1;
            }

            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/administrative/delete_attachments_view", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send("id="+String(wj_id));
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        alert("删除成功！")
                    }
                }
            };
        }
    </script>
{% endblock %}



